(function(window) {
	var app = {};
//	console.log(window);
	app.ct = window.ct;
	app.init = function() {
		this.ct.init();
		this.user = this.ct.user;
		this.lang = {};
		this.loadLang();
		this.checkLogin();
	}
	app.loadLang = function() {
		this.lang = this.ct.loadjson('js/lang/' + 'app.cn.php');
	}
	app._parseLang = function() {}

	app.box = function(title, content, width, height) {
		width = (width == undefined ? 500 : width);
		height = (height == undefined ? 500 : height);
		this.ct.box(this.lang[title], this.lang[content] == undefined ? content : this.lang[content], true, false, true, width, height, {
			'opacity': 0,
			'width': 0,
			'left': -10
		}, {
			'opacity': 0.2,
			'width': 0,
			'left': -10
		}, 'twitter-like-box', 'twitter-like-cover');
	}
	app.boxIframe = function(title, url, width, height) {
		$('#loadiframe').attr('src', url);
		this.box(title, $('#loadiframe'), width, height);
	}
	app.boxIframeAjax = function(title, url, width, height) {
		//需要设置一个公共的预加载处理逻辑
		_data=$.sync(url,function(data){return data},'html',2000);//似乎这个c超时无效
		if(_data.status=='error'){
			if(_data.error.name=='NETWORK_ERR'){
				content='NETWORK_ERROR';
			}
			else{
				content=_data.error.message;
			}
		}
		else{
			//存在样式覆盖问题，对所有内置样式前加.box-inside>
			//将外部link样式加载进来覆盖到文件内部，每个前面加.box-inside>
			//_match_css=_data.match(/<style\s?[\w=\"\'\/]+>(.+?)<\/style>/ig);
			//console.log(_match_css,_data);
			//for(_each_css in _match_css){
			//	console.log(_each_css);
			//}
			//暂时不实现这个方法
			content=_data;
		}
		this.box(title, content, width, height);
	}

	app.checkLogin = function() {
		if (!this.user.isLogin()) {
			if(this.ct.ctl.inCtlArray(this.ct.win.ctlstr,['secert-love/index.index'])){
				this.boxIframe('NO_LOGIN_TITLE', 'http://ctphp.local.com/?m=secert-love/account.login', 600, 400);	
			}
			//this.boxIframeAjax('NO_LOGIN_TITLE', 'http://ctphp.local.com/demo/phpinfo.php', 600, 400);
			//this.boxIframe('NO_LOGIN_TITLE','http://ctphp.local.com/?m=secert-love/account.login',600,400);
		}
	}

	window.app = app;
})(window);